﻿using System;
using System.Data;
using VIT.Web.UI;
using VIT.Web.Controls;
using VIT.Provider;
using System.Web.UI.WebControls;

namespace VIT.Web.Admin
{
    public partial class SupplierTrash : VITComponent
    {
        Provider.ProductSupplier obj;

        protected void Page_Load(object sender, EventArgs e)
        {
            obj = new Provider.ProductSupplier();
            pnAlert.Visible = false;
        }

        #region Methods
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select)]
        public DataTable GetData(string SortColumn)
        {
            return new Provider.ProductSupplier().GetRecycleBin(SortColumn);
        }

        public void ClearedList(string[] listId)
        {
            foreach (string id in listId)
                obj.Cleared(id);
        }

        private void setTrueVisible(System.Web.UI.HtmlControls.HtmlGenericControl control)
        {
            pnAlert.Visible = true;
            lblChon.Visible = false;
            lblPhucHoiThanhCong.Visible = false;
            lblXoaVinhVien.Visible = false;

            control.Visible = true;
        }
        #endregion

        #region Events
        protected void Delete_Click(object sender, EventArgs e)
        {
            string[] check = Request["itemCheckbox"].Split(',');
            if (check.Length > 0)
            {
                ClearedList(check);                
                setTrueVisible(lblXoaVinhVien);
                ListView.DataBind();
            }
            else setTrueVisible(lblChon);
        }

        protected void Back_Click(object sender, EventArgs e)
        {
            string[] check = Request["itemCheckbox"].Split(',');
            if (check.Length == 1)
            {
                obj.Delete(0, int.Parse(check[0]));
                setTrueVisible(lblPhucHoiThanhCong);
                ListView.DataBind();
            }
            else if (check.Length > 1) setTrueVisible(lblPhucHoiLanLuot) ; // thong bao xoa tung phan tu
            else setTrueVisible(lblChon); // thong bao chon it nhat 1 phan tu
        }

        protected void Pager_PreRender(object sender, EventArgs e)
        {
            ListView.DataBind();
        }
        #endregion
    }
}
